package com.graduation.project.controller.process;

import com.graduation.project.entity.dto.*;
import com.graduation.project.entity.dto.grade.SaveOrUpdateGradeDTO;
import com.graduation.project.entity.dto.thesis.ListThesisDTO;
import com.graduation.project.service.process.ThesisService;
import com.graduation.project.utils.FtpUtil;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/thesis")
public class ThesisController {

    @Autowired
    private ThesisService thesisService;

    /**
     * 查询论文列表数据
     * @param input 查询论文输入类
     * @return ResultUtil
     */
    @PostMapping("/post/listThesisByCondition")
    public ResultUtil<?> listThesisByCondition(@RequestBody ListThesisDTO input) {
        return thesisService.listThesisByCondition(input);
    }

    /**
     * 审核论文
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:firstDraft:audit', 'pro:finalize:audit')")
    @PutMapping("/put/auditThesis")
    public ResultUtil<?> auditThesis(@RequestBody UpdateStatusDTO input) {
        return thesisService.auditThesis(input);
    }

    /**
     * 获取当前论文得分
     * @param taskId 课题id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:finalize:grade')")
    @GetMapping("/get/getThesisGrade")
    public ResultUtil<?> getThesisGrade(@RequestParam("taskId") Long taskId) {
        return thesisService.getThesisGrade(taskId);
    }

    /**
     * 指导老师评分（定稿）
     * @param input 评分输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:finalize:grade')")
    @PostMapping("/post/gradeThesis")
    public ResultUtil<?> gradeThesis(@RequestBody SaveOrUpdateGradeDTO input) {
        return thesisService.gradeThesis(input);
    }

    /**
     * 为定稿分配评阅人
     * @param input 分配输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('group:evaluator')")
    @PutMapping("/put/allotEvaluator")
    public ResultUtil<?> allotEvaluator(@RequestBody AllotDTO input) {
        return thesisService.allotEvaluator(input);
    }

    /**
     * 为定稿分配答辩小组
     * @param input 分配输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('group:defense')")
    @PutMapping("/put/allotDefense")
    public ResultUtil<?> allotDefense(@RequestBody AllotDTO input) {
        return thesisService.allotDefense(input);
    }

    /**
     * 上传论文
     * @param input 文件上传输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:firstDraft:update', 'pro:finalize:update')")
    @PostMapping("/post/uploadThesisFile")
    public ResultUtil<?> uploadThesisFile(UploadFileDTO input) {
        return thesisService.uploadThesisFile(input);
    }

    /**
     * 删除论文
     * @param input 删除文件输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:firstDraft:update', 'pro:finalize:update')")
    @PutMapping("/put/deleteThesisFile")
    public ResultUtil<?> deleteThesisFile(@RequestBody DeleteFileDTO input) {
        return thesisService.deleteThesisFile(input);
    }

    @GetMapping("/test")
    public ResultUtil<?> test() {
        FtpUtil.upload();
        return null;
    }
}
